package View.ClienteView;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JPanel;

import Controller.ClienteController.ClienteConsultaController;
import Entidade.Cliente;
import Model.ClienteModel.ClienteConsultaModel;
import framework.component.table.TTable;
import framework.mvc.GenericView;
import java.awt.Font;

public class ClienteConsultaView extends GenericView<Cliente> {
	private static final long serialVersionUID = 7002975496345331464L;

	private JPanel panel;
	private JButton btnNovo;
	private JButton btnAlterar;
	private JButton btnExcluir;
	private JButton btnFechar;
	private TTable table;

	public ClienteConsultaView() {
		super(new ClienteConsultaController());
		setSize(new Dimension(1000, 450));
		setTitle("Fox Empresarial - Gerenciamento de Clientes");
		getContentPane().setLayout(new BorderLayout(0, 0));

		panel = new JPanel();
		getContentPane().add(panel, BorderLayout.NORTH);
		panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		btnNovo = new JButton("Novo");
		btnNovo.setName("novo");
		panel.add(btnNovo);

		btnAlterar = new JButton("Alterar");
		btnAlterar.setName("alterar");
		panel.add(btnAlterar);

		btnExcluir = new JButton("Excluir");
		btnExcluir.setName("excluir");
		panel.add(btnExcluir);

		btnFechar = new JButton("Fechar");
		btnFechar.setName("fechar");
		panel.add(btnFechar);

		table = new TTable(Cliente.class);
		table.getTable().setFont(new Font("Verdana", Font.PLAIN, 11));
		table.setColumnName("NomeCliente", "Nome");
		table.setColumnName("IdCliente", "Codigo");
		table.setColumnName("Email", "E-Mail");
		table.setColumnName("CPF_CNPJCliente", "CNPJ-CPF");
		table.setColumnName("TelefoneCliente", "Telefone");
		table.setColumnName("FantasiaCliente", "Fantasia");
		table.setColumnName("ComplementoCliente", "Complemento");

		getContentPane().add(table, BorderLayout.CENTER);

		atualizarView();
	}

	@Override
	public void atualizarView() {
		super.atualizarView();
		table.setDados(getDAO().listar());
	}

	@Override
	public void atualizarModel() {
		super.atualizarModel();
		ClienteConsultaModel model = (ClienteConsultaModel) getModel();
		model.setClienteSelecionado((Cliente) table.getSelecionado());
	}
}
